// pages/my/info.js
import {
    user,
    member
  } from "../../api/apiData"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showNav: true,
        showImg: true,
        truename:'',
        mobile:'',
        address:'',
        household_address:'',
        type:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let type = wx.getStorageSync('type')
        this.setData({
            type:type
        })
        if(type=='User'){
            user.detail({},res=>{
                this.setData({
                    truename:res.data.truename,
                    mobile:res.data.mobile,
                    address:res.data.address,
                    household_address:res.data.household_address,
                })
            })
        }
        if(type=='Member'){
            member.station.memberDetail({},res=>{
                this.setData({
                    truename:res.data.truename,
                    mobile:res.data.mobile,
                    position:res.data.position,
                    call_address:res.data.call_address,
                })
            })
        }
        
    },
    toSubmit(){
        let type =this.data.type
        if(type=='User'){
            let obj = {
                truename:this.data.truename,
                mobile:this.data.mobile,
                address:this.data.address,
                household_address:this.data.household_address
            }
            user.editInfo(obj,res=>{
                if(res.code==1){
                    wx.showToast({
                        title: res.msg,
                      })
                }else{
                    wx.showToast({
                        title: res.msg,
                        icon:'error'
                      })
                }
            })
        }else{
            let obj = {
                truename:this.data.truename,
                mobile:this.data.mobile,
                position:this.data.position,
                call_address:this.data.call_address
            }
            member.station.memberEditInfo(obj,res=>{
                if(res.code==1){
                    wx.showToast({
                        title: res.msg,
                      })
                }else{
                    wx.showToast({
                        title: res.msg,
                        icon:'error'
                      })
                }
            })
        }
      
     
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})